<!DOCTYPE html "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro"
    >
<meta charset="UTF-8">
<head th:include="include :: header"></head>

<body class="gray-bg">
<div class="wrapper wrapper-content ">
    <div class="col-sm-12">
        <div class="ibox">
            <div class="ibox-body">
                <div class="fixed-table-toolbar">
                    <div class="columns pull-right">
                        <button class="btn btn-success" onclick="query()">查询</button>
                        <button class="btn btn-success" onclick="resetParam()">重置</button>
                    </div>

                    <div class="columns pull-right col-md-2 nopadding">
                        <input class="form-control" type="text" id="orderId" placeholder="订单编号" />
                    </div>
                    <div class="columns pull-right col-md-2 nopadding">
                        <select id="returnOrderStatus" data-placeholder="退款状态" class="form-control chosen-select" tabindex="1"
                                style="width: 100%">
                            <option value="">--退款状态--</option>
                            <option value="0"> 退款中/换货中</option>
                            <option value="1"> 退款审核通过</option>
                            <option value="2"> 退款失败/换货驳回</option>
                            <option value="3"> 用户撤销</option>
                            <option value="4"> 用户已退/换货</option>
                            <option value="5"> 退款完成/换货已发货</option>
                            <option value="6"> 换货完成</option>
                        </select>
                    </div>
                    <div class="columns pull-right col-md-2 nopadding">
                        <input class="form-control" type="text" id="reqReturnTime" name="reqReturnTime" placeholder="申请退款时间" />
                    </div>

                </div>
            </div>
            <table id="exampleTable" data-mobile-responsive="true">
            </table>
        </div>
    </div>
</div>
</div>
<!--shiro控制bootstraptable行内按钮看见性 来自bootdo的创新方案 -->
<div>
    <script type="text/javascript">
        var s_edit_h = '';
    </script>
</div>
<div >
    <script type="text/javascript">
        s_edit_h = '';
    </script>
</div>
<div>
    <script type="text/javascript">
        var s_edit_d = '';
    </script>
</div>
<div >
    <script type="text/javascript">
        s_edit_d = '';
    </script>
</div>

</div>
<div th:include="include :: footer"></div>
<script type="text/javascript">

    var prefix = "/app/orderReturn";
    $(function () {
        $('#reqReturnTime').val('');
        load();
    });
    $('input[name="reqReturnTime"]').daterangepicker({
            locale: {
                format: 'YYYY-MM-DD'
            }
        },
        function(start, end, label) {

            // alert("A new date range was chosen: " + start.format        ('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD'));
        });

    function resetParam() {
        $('#orderId').val('');
        $('#returnOrderStatus').val('');
        $('#reqReturnTime').val('');
        reLoad();
    }

    function load() {
        $('#exampleTable')
            .bootstrapTable(
                {
                    method: 'get', // 服务器数据的请求方式 get or post
                    url: prefix + "/list", // 服务器数据的加载地址
                    //showRefresh: true,
                    //	showToggle : true,
                    //	showColumns : true,
                    iconSize: 'outline',
                    toolbar: '#exampleToolbar',
                    striped: true, // 设置为true会有隔行变色效果
                    dataType: "json", // 服务器返回的数据类型
                    pagination: true, // 设置为true会在底部显示分页条
                    // queryParamsType : "limit",
                    // //设置为limit则会发送符合RESTFull格式的参数
                    singleSelect: false, // 设置为true将禁止多选
                    // contentType : "application/x-www-form-urlencoded",
                    // //发送到服务器的数据编码类型
                    pageSize: 10, // 如果设置了分页，每页数据条数
                    pageNumber: 1, // 如果设置了分布，首页页码
                    //search : true, // 是否显示搜索框
                    showColumns: false, // 是否显示内容下拉框（选择显示的列）
                    sidePagination: "server", // 设置在哪里进行分页，可选值为"client" 或者 "server"
                    queryParams: function (params) {
                        return {
                            //说明：传入后台的参数包括offset开始索引，limit步长，sort排序列，order：desc或者,以及所有列的键值对
                            limit: params.limit,
                            offset: params.offset,
                            orderId: $.trim($('#orderId').val()),
                            returnOrderStatus:$('#returnOrderStatus').val(),
                            reqReturnTime:$('#reqReturnTime').val()
                        };
                    },
                    // //请求服务器数据时，你可以通过重写参数的方式添加一些额外的参数，例如 toolbar 中的参数 如果
                    // queryParamsType = 'limit' ,返回参数必须包含
                    // limit, offset, search, sort, order 否则, 需要包含:
                    // pageSize, pageNumber, searchText, sortName,
                    // sortOrder.
                    // 返回false将会终止请求
                    columns: [
                        {
                            field: 'returnOrderId',
                            title: '申请退款编号'
                        },
                        {
                            field: 'orderId',
                            title: '订单编号'
                        },
                        {
                            field:'returnTotalAmt',
                            title:'退款总金额'
                        },
                        {
                            field: 'returnOrderStatus',
                            title: '退款状态',
                            formatter: function (value, row, index) {
                                if (row.returnType == 1) {
                                    if (value == 0) {
                                        return '<span class="label label-primary">换货中</span>';
                                    } else if (value == 1) {
                                        return '<span class="label label-success">换货审核通过</span>';
                                    }else if(value == 2) {
                                        return '<span class="label label-danger">换货驳回</span>';
                                    }else if(value == 3) {
                                        return '<span class="label label-danger">用户撤销</span>';
                                    }else if(value == 4) {
                                        return '<span class="label label-danger">用户已换货</span>';
                                    }else if(value == 5) {
                                        return '<span class="label label-danger">换货已发货</span>';
                                    }else if(value == 6) {
                                        return '<span class="label label-danger">换货完成</span>';
                                    }
                                }else {
                                    if (value == 0) {
                                        return '<span class="label label-primary">退款中</span>';
                                    } else if (value == 1) {
                                        return '<span class="label label-success">退款审核通过</span>';
                                    }else if(value == 2) {
                                        return '<span class="label label-danger">退款失败</span>';
                                    }else if(value == 3) {
                                        return '<span class="label label-danger">用户撤销</span>';
                                    }else if(value == 4) {
                                        return '<span class="label label-danger">用户已退货</span>';
                                    }else if(value == 5) {
                                        return '<span class="label label-danger">退款完成</span>';
                                    }
                                }
                            }
                        },
                        {
                            field: 'reqReturnTime',
                            title: '申请退款时间'
                        },
                        {
                            title: '操作',
                            field: 'returnOrderId',
                            align: 'center',
                            formatter: function (value, row, index) {
                                if (row.returnType == 2) {
                                    var dtl = '<a class="btn btn-success btn-sm '  + '" href="#" mce_href="#" title="详情" onclick="dtl(\''
                                        + value
                                        + '\')"><i class="fa fa-address-card-o"></i>详情</a> ';
                                    var e = '';
                                    if (row.returnOrderStatus == 0 || row.returnOrderStatus == 4) {
                                        e = '<a class="btn btn-primary btn-sm ' + s_edit_h + '" href="#" mce_href="#" title="编辑" onclick="edit(\''
                                            + value
                                            + '\')"><i class="fa fa-address-card-o"></i>退款</a> ';
                                    }
                                    return dtl + e;
                                }else {
                                    var dtl = '<a class="btn btn-success btn-sm '  + '" href="#" mce_href="#" title="详情" onclick="dtl(\''
                                        + value
                                        + '\')"><i class="fa fa-address-card-o"></i>详情</a> ';
                                    var e = '';
                                    if (row.returnOrderStatus == 0 || row.returnOrderStatus == 4) {
                                        e = '<a class="btn btn-success btn-sm ' + s_edit_h + '" href="#" mce_href="#" title="编辑" onclick="edit(\''
                                            + value
                                            + '\')"><i class="fa fa-address-card-o"></i>换货</a> ';
                                    }
                                    return dtl + e;
                                }
                            }
                        }]
                });
    }

    function query() {
        var opt = {
            query: {
                orderId: $.trim($('#orderId').val()),
                returnOrderStatus:$('#returnOrderStatus').val(),
                reqReturnTime:$('#reqReturnTime').val()
            }
        };
        $('#exampleTable').bootstrapTable('refresh', opt);
    }

    function reLoad() {
        var opt = {
            query: {
                limit: 10,
                offset: 0
            }
        };
        $('#exampleTable').bootstrapTable('refresh', opt);
    }

    function edit(id) {
        layer.open({
            type: 2,
            title: '退款',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['1150px', '720px'],
            content: prefix + '/edit/' + id// iframe的url
        });
    }

    function dtl(id) {
        layer.open({
            type: 2,
            title: '退款详情',
            maxmin: true,
            shadeClose: false, // 点击遮罩关闭层
            area: ['1150px', '620px'],
            content: prefix + '/dtl/' + id// iframe的url
        });
    }
</script>
</body>
</html>